package user;

import booklist.BookList;
import operation.*;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-04-10
 * Time: 15:58
 */
public class NormalUser extends User{

    public NormalUser(String name) {
        super(name);
        //实现操作数组中的内容
        this.dooperation = new Operation[] {
                new ExitOperation(),
                new SearchOperation(),
                new Lendbook(),
                new ReturnBook(),
                new ShowOperation()
        };
    }
    //重写操作数组的方法，发生动态绑定
    @Override
    public void doOperation(int choice, BookList bookList) {
        dooperation[choice].work(bookList);
    }

    //普通用户菜单
    @Override
    public int menu() {
        System.out.println("=========普通用户菜单=========");
        System.out.println("Hello" + ", " + this.userName + "欢迎来到图书管理系统");
        System.out.println("1.查找图书");
        System.out.println("2.借阅图书");
        System.out.println("3.归还图书");
        System.out.println("0.退出系统");
        System.out.println("请选择你的操作：");
        Scanner scan = new Scanner(System.in);
        do {
            int choice = scan.nextInt();
            if(choice >= 0 && choice <= 3) {
                return choice;
            } else {
                System.out.println("输入错误，请重新输入！");
            }
        }while(true);
    }
}
